package com.example.nonggo.presenter;

import android.provider.SyncStateContract;

import com.example.nonggo.Constants;
import com.example.nonggo.base.BasePresenter;
import com.example.nonggo.bean.LoginNameRes;
import com.example.nonggo.bean.LoginRes;
import com.example.nonggo.contract.LocationContract;
import com.example.nonggo.contract.LoginContract;
import com.example.nonggo.model.MainModel;
import com.tencent.mmkv.MMKV;


import org.jetbrains.annotations.NotNull;

import static com.example.nonggo.Constants.PROVINCE;


/**
 * @Author Kotlin MVP Plugin
 * @Date 2025/03/01
 * @Description input description
 **/
public class MainPresenter extends  BasePresenter<LoginContract.View>  {
    private final MainModel loginModel;

    public MainPresenter(MainModel loginModel) {
        this.loginModel = loginModel;
    }


    public void getVerCode(String num) {
        loginModel.getVerCode(num, new LoginContract.Presenter() {
            @Override
            public void getVerCodeSuccess() {
              getView().getVerCodeSuccess();
            }

            @Override
            public void getVerCodeFail() {
                getView().getVerCodeFail();
            }
        });
    }
    public void getLocation(String lon, String lat){
        loginModel.getLocationName(lon, lat, data -> {
            MMKV.defaultMMKV().putString(Constants.CITY,data.getCity());
            MMKV.defaultMMKV().putString(Constants.COUNTY,data.getCounty());
            MMKV.defaultMMKV().putString(Constants.FULL_NAME,data.getFullName());
            MMKV.defaultMMKV().putString(Constants.PROVINCE, data.getProvince());
        });
    }

    public void login (String mobile, String code){
        loginModel.login(mobile, code, new LoginContract() {
            @Override
            public void loginSuccess(LoginRes data) {
                //把uid存起来
                MMKV.defaultMMKV().putInt(Constants.USERID,data.getUserId());
                MMKV.defaultMMKV().putString(Constants.ACCESS_TOKEN,data.getAccessToken());
                MMKV.defaultMMKV().putString(Constants.REFRESH_TOKEN,data.getRefreshToken());
                MMKV.defaultMMKV().putString(Constants.MOBILE,mobile);
                getView().loginSuccess();
            }
        });
    }


}
